package com.cn.news.controller;

import com.cn.common.pojo.NItemModel;
import com.cn.common.pojo.ResultModel;
import com.cn.news.service.NitemService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

@Api(tags = "新闻标题信息")
@RestController
@RequestMapping("nitem")
public class NitemController {
    private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String date= DATE_FORMAT.format(new Date());
    @Autowired
    NitemService nitemService;
    @GetMapping("nitem")
    public ResultModel nitem(){
        ResultModel nitem = nitemService.nitem();
        return nitem;
    }
    @GetMapping("delete")
    public ResultModel delete(int id){
        ResultModel delete = nitemService.delete(id);
        return delete;
    }
    @PostMapping("update")
    public ResultModel update(NItemModel nItemModel){
        ResultModel update = nitemService.update(nItemModel);
        return update;
    }
    @PostMapping("insert")
    public ResultModel insert(NItemModel nItemModel){
        ResultModel insert = nitemService.insert(nItemModel);
        return insert;
    }
    @PostMapping(value = "enable")
    public ResultModel enable(int id){
        ResultModel enable = nitemService.enable(id);
        return enable;
    }
    @GetMapping("findById")
    public ResultModel findById(int id){
        ResultModel findById = nitemService.findById(id);
        return findById;
    }
    @GetMapping("limit")
    public ResultModel getCompan(NItemModel nItemModel,int limit,int page){
        nItemModel.setPageNum(page);
        nItemModel.setPageSize(limit);
        ResultModel resultModel = nitemService.limit(nItemModel);
        return resultModel;
    }
}
